package com.skt.common_hr.resupport.model
{
	import com.skt.common_hr.common.approval.IRequestApprovalProxy;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.resupport.model.vo.ResupportMoneyVO;
	import com.wcl.utils.NumberUtil;
	
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;

	public class ResupportApprovalProxy extends CommonProxy implements IRequestApprovalProxy
	{
		public static const NAME:String = "MedicalMoneyApprovalProxy";

		public var dataProvider:ResupportMoneyVO;

		private var templateHTML:String = "";
		/**
		 * 생성자
		 *
		 * @param
		 * @return void
		 */
		public function ResupportApprovalProxy(data:Object=null)
		{
			super(NAME, data);
			loadTemplate();
		}

		private var _key:String = "";
		public function get key():String
		{
			return _key;
		}
		public function set key(k:String):void
		{
			_key = k;
		}


		public function get title():String
		{
			var tmp:String = "의료비 신청";
			//tmp += " (" + dataProvider.ZTEXT + ")"
			return tmp;
		}

		public function get content():String
		{
			return buildHTML(dataProvider);
		}

		public function get appCode():String
		{
			return "11"; 	//
		}


 		private function loadTemplate():void
		{
			var request:URLRequest = new URLRequest("assets/template/medicalmoney.tmp");
			loader.addEventListener(Event.COMPLETE, templateResult);
			loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

            try {
                loader.load(request);
            } catch (error:Error) {
                trace("Unable to load requested document.");
            }
		}

		private function templateResult(event:Event):void
		{
			templateHTML = loader.data;
		}

		private function ioErrorHandler(event:IOErrorEvent):void
		{
			trace("ioErrorHandler: " + event);
		}

 		private function buildHTML(vo:ResupportMoneyVO):String
		{
			var htmlAll:String = templateHTML;
			var htmlBlock:String = "";

			var ptnCname:RegExp  	= /__EMFTX__/;
			var ptnIDATE_F:RegExp  	= /__IDATE_F__/;
			var ptnSPMON:RegExp  	= /__SPMON__/;
			var ptnHOWMANY:RegExp  	= /__HOWMANY__/;
			var ptnHOWMUCH:RegExp  	= /__HOWMUCH__/;


			//var ptnFtext:RegExp  = /__FTEXT__/;
			//var ptnCosten:RegExp = /__COSTEN__/;

			htmlAll = htmlAll.replace(ptnCname, vo.EMFTX);
			htmlAll = htmlAll.replace(ptnHOWMANY, vo.HOWMANY + '건');
			htmlAll = htmlAll.replace(ptnHOWMUCH, NumberUtil.NumberFormat(vo.HOWMUCH) +'원');

//			if(vo.COSEL == 'X') {
//				htmlAll = htmlAll.replace(ptnCosten, vo.COSTEN);
//			} else {
//				htmlAll = htmlAll.replace(ptnCosten, '');
//			}
			return htmlAll;
		}
	}
}